/**
 *
 */

(function(){
	var Matrix22 = function Matrix22( angle ){
		var c;
		var s;
		
		if( arguments.length === 2 &&
				arguments[0].type === Box2d.Math.Vector2.type &&
				arguments[1].type === Box2d.Math.Vector2.type){
			this.col1 = arguments[0];
			this.col2 = arguments[1];
			return;
		}else if( arguments.length === 1 &&
				typeof arguments[0] === 'number' ){

			c = Math.cos( angle );
			s = Math.sin( angle );
			
			this.col1 = new Box2d.Math.Vector2( c, s );
			this.col2 = new Box2d.Math.Vector2( -s, c );
		}else if( arguments.length === 2 &&
				arguments[0].type && arguments[0].type === Box2d.Math.Vector2.type &&
				arguments[1].type && arguments[1].type === Box2d.Math.Vector2.type ){
			this.col1 = arguments[0];
			this.col2 = arguments[1];
		}else{
			this.col1 = new Box2d.Math.Vector2();
			this.col2 = new Box2d.Math.Vector2();
		}
	};
	var proto = Matrix22.prototype;
	
	Matrix22.type = 'Matrix22';
	proto.type = Matrix22.type;
	
	proto.transpose = function transpose(){
		return new Box2d.Math.Matrix22(
			new Box2d.Math.Vector2( this.col1.x, this.col2.x ),
			new Box2d.Math.Vector2( this.col1.y, this.col2.y )
		);
	};
	
	proto.set = function set( vec1, vec2 ){
		this.col1 = vec1;
		this.col2 = vec2;
	};
	
	proto.mul = function mul( x ){
		var output;

		if( x instanceof Box2d.Math.Vector2 ){
			output = new Box2d.Math.Vector2(
				this.col1.x * x.x + this.col2.x * x.y,
				this.col1.y * x.x + this.col2.y * x.y
			);
		}else if( x instanceof Box2d.Math.Matrix22 ){
			output = new Box2d.Math.Matrix22(
				this.mul( x.col1 ),
				this.mul( x.col2 )
			);
		}else{
			throw 'Argument must be of type "Vector2" or "number"';
		}
		return output;
	}
	
	proto.abs = function abs(){
		return new Box2d.Math.Matrix22(
			Box2d.Math.Vector2.abs( this.col1 ),
			Box2d.Math.Vector2.abs( this.col2 )
		);
	}
	
	Box2d.Math.Matrix22 = Matrix22;
})();